<template>
  <ul v-loading="loading" class="songList">
    <li v-for="(s, index) in songList" :key="s.id" @click="select(s, index)">
      <div
        v-show="numberVisible"
        class="number"
        :class="{
          'iconfont purple-first': index === 0,
          'iconfont purple-second': index === 1,
          'iconfont purple-third': index === 2
        }"
      >
        {{ index >= 3 ? index + 1 : '' }}
      </div>
      <div class="left">
        <div class="name">{{ s.name }}</div>
        <div class="info">{{ `${s.singer}·${s.album}` }}</div>
      </div>
      <i class="iconfont purple-play2"></i>
    </li>
  </ul>
</template>

<script>
export default {
  name: 'SongList',
  props: {
    songList: {
      required: true,
      type: Array
    },
    numberVisible: {
      type: Boolean,
      default: false
    }
  },
  emit: ['select'],
  computed: {
    loading() {
      return this.songList.length === 0
    }
  },
  methods: {
    select(song, index) {
      this.$emit('select', { song, index })
    }
  }
}
</script>

<style lang="scss" scoped>
.songList {
  padding: 20px 30px;
  min-height: 200px;
  > li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
    border-bottom: 1px solid $color-line;
    .number {
      width: 35px;
      height: 25px;
      line-height: 25px;
      font-size: 18px;
      color: $color-list-title;
    }
    .number.iconfont {
      position: relative;
      right: 5px;
      font-size: 25px;
    }
    .left {
      display: flex;
      flex-direction: column;
      justify-content: center;
      width: 80%;
      > div {
        padding: 4px 0;
        font-size: 14px;
      }
      .name {
        @include omit;
      }
      .info {
        @include omit;
        font-size: 12px;
        color: grey;
      }
    }
    .purple-play2 {
      font-size: 20px;
      color: $color-button-little;
    }
  }
}
</style>
